package com.hao.study.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hao.study.entity.OpLog;
import com.hao.study.service.OpLogService;
import com.hao.study.mapper.OpLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【b_op_log】的数据库操作Service实现
* @createDate 2024-06-13 09:23:42
*/
@Service
public class OpLogServiceImpl extends ServiceImpl<OpLogMapper, OpLog>
    implements OpLogService{
    @Autowired
    OpLogMapper mapper;

    @Override
    public PageInfo<OpLog> getOpLogList(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<OpLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderBy(true, false, "re_time");
        if (StringUtils.isNotBlank(keyword)){
            queryWrapper.eq("re_ip",keyword);
        }
        return PageInfo.of(mapper.selectList(queryWrapper));
    }

    @Override
    public PageInfo<OpLog> loginLogList(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<OpLog> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("re_url", "/api/user/userLogin");
        queryWrapper.orderBy(true, false, "re_time");
        if (StringUtils.isNotBlank(keyword)){
            queryWrapper.eq("re_id",keyword);
        }
        return PageInfo.of(mapper.selectList(queryWrapper));
    }

    @Override
    public void createOpLog(OpLog opLog) {
        mapper.insert(opLog);
    }

    @Override
    public void deleteOpLog(String id) {
        mapper.deleteById(id);
    }

    @Override
    public void updateOpLog(OpLog opLog) {
        mapper.updateById(opLog);
    }

}




